package com.example.demo.controller;

import com.example.demo.aip.TokenService;
import com.example.demo.common.ResponseDTO;
import com.example.demo.tags.AutoIdempotent;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
public class BusinessController {


    @Resource
    private TokenService tokenService;

    Gson gson = new GsonBuilder().serializeNulls().create();


    @PostMapping("/get/token")
    public ResponseDTO<String> getToken() {
        String token = tokenService.createToken();
        if (StringUtils.isNotEmpty(token)) {
            ResponseDTO<String> resultVo = ResponseDTO.success(token, null);
            return resultVo;
        }
        return ResponseDTO.fail(null, null);
    }


    @AutoIdempotent
    @PostMapping("/test/Idempotence")
    public ResponseDTO<String> testIdempotence() {
        String businessResult = "";

        return ResponseDTO.success(null, null);
    }
}